import axios from '~/plugins/axios'

const variety = {
  state: {
    variety: []
  },

  mutations: {
    SET_VARIETY (state, payload) {
      state.variety = payload
    }
  },

  actions: {
    async nuxtServerInit ({commit}) {
      const {data: {data = {}}} = await axios.get(`/search/findGoodsCategoryList`)
      commit('SET_VARIETY', data.map((item) => ({ name: item.goodsCategoryName, id: item.goodsCategoryId})))
    }
  }
}

export default variety
